package com.hfut.manage.controller;


import com.hfut.manage.pojo.JobPosition;
import com.hfut.manage.pojo.Result;
import com.hfut.manage.pojo.RewardPunishment;
import com.hfut.manage.service.IRewardPunishmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reward-punishment")
public class RewardPunishmentController {

    @Autowired
    private IRewardPunishmentService rewardPunishmentService;

    @GetMapping
    public Result list() {
        return Result.success(rewardPunishmentService.lambdaQuery().orderByAsc(RewardPunishment::getId).list());
    }

    @PostMapping
    public Result save(@RequestBody RewardPunishment rewardPunishment) {
        rewardPunishmentService.save(rewardPunishment);
        return Result.success();
    }

    @PutMapping
    public Result updata(@RequestBody RewardPunishment rewardPunishment){
        rewardPunishmentService.updateById(rewardPunishment);
        return Result.success();
    }

    @GetMapping("/{teacherid}")
    public Result getById(@PathVariable("teacherid") Long teacherId) {
        List<RewardPunishment> rewardPunishments = rewardPunishmentService.lambdaQuery()
                .eq(RewardPunishment::getTeacherId, teacherId)
                .list();
        return Result.success(rewardPunishments);
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Long id) {
        boolean success = rewardPunishmentService.removeById(id);
        if (!success) {
            return Result.error(500, "删除部门失败");
        }
        return Result.success();
    }
}
